package com.bigShen.mybatis.official.factory.singleton;

/**
 * @author : lei.shen
 * @date : 2018/11/21
 */
public class FactorySingleton {


   /* // hungry singleton
    private static final  FactorySingleton FACTORY_SINGLETON = new FactorySingleton();

    private FactorySingleton() {

    }

    public static FactorySingleton getInstance() {

        return FACTORY_SINGLETON;

    }*/

   // Lazy one
    /*private static FactorySingleton FACTORY_SINGLETON = null;

    public static synchronized FactorySingleton getInstance(){

        if (null == FACTORY_SINGLETON) {
            FACTORY_SINGLETON = new FactorySingleton();
        }
        return FACTORY_SINGLETON;
    }*/

    // Lazy two
    /*private static FactorySingleton FACTORY_SINGLETON = null;

    public static FactorySingleton getInstance(){

        if (null == FACTORY_SINGLETON) {
            synchronized (FactorySingleton.class) {
               if (null == FACTORY_SINGLETON) {
                   FACTORY_SINGLETON = new FactorySingleton();
               }
            }
        }
        return FACTORY_SINGLETON;
    }*/


    // static inner class
    static class FactorySingletonHolder {
        public static final FactorySingleton FACTORY_SINGLETON = new FactorySingleton();
    }

    public static FactorySingleton getInstance(){
        return FactorySingletonHolder.FACTORY_SINGLETON;
    }

}


